package com.beici.waterghost.security;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.beici.waterghost.except.selectError;
import com.beici.waterghost.model.login.userLogin;
import com.beici.waterghost.model.resultes;
import com.beici.waterghost.service.impl.userServiceImpl;
import com.beici.waterghost.service.loginCRUDService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class userDetailsServiceImp implements UserDetailsService {
    @Autowired
    private loginCRUDService userService;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        // 判断用户传进来的用户是否存在
        userLogin user = userService.selectOne(new QueryWrapper<userLogin>().eq("user_phone", username));
        if (user==null){
            throw new selectError("账号不存在");
        }
        // 不为空的话那么我们就返回该对象
        return user;
    }
}
